import Vue from 'vue';
import siteInfo from '../../siteinfo.js';

const state = {
	auth_page: {},
	bar_title: {},
	cat_style: {},
	copyright: {},
	mall: {
		setting: {
			theme_color: 'classic-red'
		}
	},
	navbar: {
		navs: []
	},
	tabBarLoacl: [{
			active_color: "rgb(238, 127, 43)",
			active_icon: siteInfo.imgroot + "/web/uploads/mall1/20210610/9258b43b307dbeb5021302e05b951949.png",
			color: "#000000",
			icon: siteInfo.imgroot + "/web/uploads/mall1/20210610/9258b43b307dbeb5021302e05b951949.png",
			key: "",
			open_type: "redirect",
			text: "我的直播 4500家实体店",
			url: "/plugins/mch_solitaire/jewellery-main/jewellery-main",
		},
		{
			active_color: "rgb(238, 127, 43)",
			active_icon: siteInfo.imgroot + "/web/uploads/mall1/20210610/b823ef8f546677747572e775180a2587.png",
			color: "#000000",
			icon: siteInfo.imgroot + "/web/uploads/mall1/20210610/b823ef8f546677747572e775180a2587.png",
			key: "live",
			open_type: "redirect",
			text: "品类直播 好货快快抢",
			url: "/pages/gospeed/index",
		},
		// /web/uploads/mall1/20210622/d2cf518b02d32c276d4f6aec2c0dcac3.jpg
		{
			active_color: "rgb(238, 127, 43)",
			active_icon: siteInfo.imgroot + "/web/uploads/tabbar/hi.gif",
			color: "#000000",
			icon: siteInfo.imgroot + "/web/uploads/tabbar/hi.gif",
			key: "live",
			open_type: "redirect",
			text: "1276个主播 店主带货",
			url: "/pages/sixty/index",
		},
		{
			active_color: "rgb(238, 127, 43)",
			active_icon: siteInfo.imgroot + "/web/uploads/mall1/20210610/e9b1b40a881679c04d574dcce117045c.png",
			color: "#000000",
			icon: siteInfo.imgroot + "/web/uploads/mall1/20210610/e9b1b40a881679c04d574dcce117045c.png",
			key: "mch",
			open_type: "redirect",
			text: "挣钱养家 我的珠宝店",
			url: "/pages/store/mine/mine",
		},
		{
			active_color: "rgb(238, 127, 43)",
			active_icon: siteInfo.imgroot + "/web/uploads/mall1/20210610/38166233a33f3d532fd7d0a70736b722.png",
			color: "#000000",
			icon: siteInfo.imgroot + "/web/uploads/mall1/20210610/38166233a33f3d532fd7d0a70736b722.png",
			open_type: "redirect",
			text: "直播收藏 个人中心",
			url: "/pages/user-center/user-center",
		},
	],
	plugin: {
		vip_card: {
			setting: {
				background: '#f7f7f7'
			}
		}
	},
	share_setting: [],
	share_setting_custom: {},
	user_center: {},
	__wxapp_img: {},
	theme: "classic-red",
	windowHeight: {
		height: 0,
		width: 0,
		boolean: false
	},
};

const getters = {
	getNavBar(state) {
		return state.navbar;
	},
	getNavBarNavs(state) {
		for (let i = 0, len = state.navbar.navs.length; i < len; i++) {}
	},
	getUserCenter(state) {
		return state.user_center;
	},
	getWxappImg(state) {
		return state.__wxapp_img;
	},
	getCatStyle(state) {
		return state.cat_style;
	},
	getVip(state) {
		return state.plugin.vip_card;
	},
	getVideo(state) {
		return state.mall.setting.is_goods_video;
	},
	getShowCart(state) {
		return state.mall.setting.is_show_cart;
	},
	getTheme(state) {
		return state.mall.setting.theme_color;
	},
	getSetting(state) {
		return state.mall.setting;
	}
};

const mutations = {
	mutSetConfig(state, data) {
		for (let item in data) {
			if (item === 'navbar') {
				for (let i = 0; i < data[item].navs.length; i++) {
					data[item].navs[i].id = i;
				}
			}
			state[item] = data[item];
		}
	},
	mutSetHeight(state, data) {
		state.windowHeight = data;
	}
};

const actions = {
	actionGetConfig(context) {
		Vue.prototype.$mallConfig.getConfig().then(response => {
			context.commit('mutSetConfig', response);
		}).catch(() => {});
	},
	actionHeight(context, data) {
		context.commit("mutSetHeight", data);
	},
	actionResetConfig(context) {
		Vue.prototype.$mallConfig.resetConfig();
		Vue.prototype.$mallConfig.getConfig().then(response => {
			context.commit('mutSetConfig', response);
		}).catch(() => {});
	}
};

export default {
	namespaced: true,
	state,
	getters,
	mutations,
	actions
}
